package qs.ipeControls
{
import mx.collections.ArrayCollection;
import mx.controls.ComboBox;
import mx.controls.Label;

import qs.ipeControls.classes.IPEBase;

[Event(name="change", type="mx.events.ListEvent")]
public class IPEComboBox extends IPEBase
{
public function IPEComboBox():void
{
super();
this.nonEditableControl = new Label();
this.editableControl = new ComboBox();
facadeEvents(editableControl,"change");
}

override protected function commitEditedValue():void
{
    Label(this.nonEditableControl).text = ComboBox(this.editableControl).selectedLabel;
    
    
}

private function get comboBox():ComboBox { return ComboBox(this.editableControl); }
private function get label():Label { return Label(this.nonEditableControl); }

[Bindable("change")]
public function get text():String { return this.comboBox.selectedLabel; }
public function set text(text:String):void
{
    this.label.text = text;
    for(var i:int=0; i<(ArrayCollection(comboBox.dataProvider).length)-1; i++)
    {
        var tmpObj:Object = ArrayCollection(comboBox.dataProvider).getItemAt(i);
        if(tmpObj.hasOwnProperty("label")){
        if(tmpObj.label == text)
            this.comboBox.selectedIndex = i;}
    }
}
public function get selectedItem():Object { return this.comboBox.selectedItem; }
public function set selectedItem(item:Object):void { this.comboBox.selectedItem = item; }
public function get selectedIndex():int { return this.comboBox.selectedIndex; }
public function set selectedIndex(index:int):void
{
    this.comboBox.selectedIndex = index;
   //BJ - if object has no label property this will hang here
  // var tmpObj:Object = ArrayCollection(comboBox.dataProvider).getItemAt(index);
  //this.label.text = tmpObj.label;
}
public function get dataProvider():Object { return this.comboBox.dataProvider; }
public function set dataProvider(provider:Object):void { 
this.comboBox.dataProvider = provider;}
public function get labelField():String { return this.comboBox.labelField; }
public function set labelField(labelField:String):void { this.comboBox.labelField = labelField; }
//bj
public function get prompt():String { return this.prompt; }
public function set prompt(text:String):void { this.comboBox.prompt = text; }


}

}